﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using CapaEntidades;

namespace CapaDatos
{
    public class daCliente
    {
        public static List<enCliente> spClienteXRazonSocial(String prmRazSocial)
        {
            SqlConnection cn = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            List<enCliente> lstCliente = null;
            try
            {

                cn = Conexion.getConexion();
                cmd = new SqlCommand("spClienteXRazonSocial", cn);
                cmd.Parameters.AddWithValue("@cli_razonSocial", prmRazSocial);
                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                dr = cmd.ExecuteReader();
                lstCliente = new List<enCliente>();
                while (dr.Read())
                {

                    enCliente cliente = new enCliente();
                    cliente.idCliente = Convert.ToInt32(dr[0].ToString());
                    cliente.razonSocial = dr[1].ToString();
                    cliente.rucdni = dr[2].ToString();
                    lstCliente.Add(cliente);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                dr.Close();
                cn.Close();
            }
            return lstCliente;

        }


        public static List<enCliente> spListarClienteAll()
        {
            SqlConnection cn = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            List<enCliente> lstCliente = null;
            try
            {

                cn = Conexion.getConexion();
                cmd = new SqlCommand("wsp_listarClienteAll", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                dr = cmd.ExecuteReader();
                lstCliente = new List<enCliente>();
                while (dr.Read())
                {

                    enCliente cliente = new enCliente();
                    cliente.idCliente = Convert.ToInt32(dr[0].ToString());
                    cliente.razonSocial = dr[1].ToString();
                    cliente.rucdni = dr[2].ToString();
                    lstCliente.Add(cliente);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                dr.Close();
                cn.Close();
            }
            return lstCliente;
        }
    }
}
